/*
 * Copyright 2008 Lucifer Lu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;

namespace SilverChart.Core.Log {
    /// <summary>
    /// Description of AbstractBrowserOutput.
    /// </summary>
    abstract class AbstractBrowserOutput : LogOutput {
        private String loggerName;
        private LogMessageFormater formater;

        public AbstractBrowserOutput(String loggerName, LogMessageFormater formater) {
            this.loggerName = loggerName;
            this.formater = formater;
        }

        public void fatal(String log, DateTime time, String codeFile, Int32 lineNo, Exception e) {

        }

        public void error(String log, DateTime time, String codeFile, Int32 lineNo, Exception e) {

        }

        public void warn(String log, DateTime time, String codeFile, Int32 lineNo, Exception e) {
            if (Logger.OutputDiv != null) {
                String loggedMessage = formater.formatWarnMessage(log, time, codeFile, lineNo, e);
                output(PreprocessMessage(loggedMessage));
            }
        }

        public void info(String log, DateTime time, String codeFile, Int32 lineNo) {
            if (Logger.OutputDiv != null) {
                String loggedMessage = formater.formatInfoMessage(log, time, codeFile, lineNo);
                output(PreprocessMessage(loggedMessage));
            }
        }

        public void debug(String log, DateTime time, String codeFile, Int32 lineNo) {
            if (Logger.OutputDiv != null) {
                try {
                    String loggedMessage = formater.formatDebugMessage(log, time, codeFile, lineNo);
                    output(PreprocessMessage(loggedMessage));
                }
                catch {
                }
            }
        }

        protected virtual String PreprocessMessage(String logMessage) {
            return logMessage.Replace("\n", "<br />").Replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;");
        }

        protected abstract void output(String loggedMessage);
        public abstract void alert(String message, String codeFile, Int32 lineNo);
    }
}
